package com.shop2cn.iapi.wxcomponent.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.wxcomponent.parameter.GetMchChargeStatusAndMoneyBean;
import com.shop2cn.iapi.wxcomponent.service.GetMchChargeStatusAndMoneyCall;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.WxComponentService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*查询白名单付费状态和金额Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMchChargeStatusAndMoney{
	private static GetMchChargeStatusAndMoneyBean getmchchargestatusandmoneyBean;
	private static GetMchChargeStatusAndMoneyCall getmchchargestatusandmoneyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询付费状态和金额Test");
	}
	
	
	@Before
	public void caseUp() {
		getmchchargestatusandmoneyBean=new GetMchChargeStatusAndMoneyBean();
		getmchchargestatusandmoneyCall=new GetMchChargeStatusAndMoneyCall();
	}
	

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmchchargestatusandmoneyCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchChargeStatusAndMoney_001() {
		Logger.start(true,"在白名单小程序查询，成功");
		try {
            int mchid= 500009815;
            JsonObject getMchAppAllStatus = GodmchManageCallService.GetMchAppAllStatus(mchid);
            Logger.verifyEquals(1, getMchAppAllStatus.get("chargeStatus").getAsInt(),"付费状态");
            
            getmchchargestatusandmoneyBean.setMchId(mchid);
			getmchchargestatusandmoneyCall.setData(getmchchargestatusandmoneyBean);
			getmchchargestatusandmoneyCall.callService();			
			Logger.verifyEquals("200", getmchchargestatusandmoneyCall.getString("code"), "验证code");
			
			
			JsonObject data = getmchchargestatusandmoneyCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals("null",data.get("wxAppStatus").toString(), "验证wxAppStatus");
			Logger.verifyEquals("0.01", data.get("money").getAsString(), "验证money");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchChargeStatusAndMoney_002() {
		Logger.start(true,"已经付费查询，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("mark", mchid);
            getmchchargestatusandmoneyBean.setMchId(mchid);
            
            
			getmchchargestatusandmoneyCall.setData(getmchchargestatusandmoneyBean);
			getmchchargestatusandmoneyCall.callService();			
			Logger.verifyEquals("200", getmchchargestatusandmoneyCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchChargeStatusAndMoney_003() {
		Logger.start(true,"未付费进行查询，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("mark", mchid);
            getmchchargestatusandmoneyBean.setMchId(mchid);
            
            
			getmchchargestatusandmoneyCall.setData(getmchchargestatusandmoneyBean);
			getmchchargestatusandmoneyCall.callService();			
			Logger.verifyEquals("200", getmchchargestatusandmoneyCall.getString("code"), "验证code");
			
			double money = getmchchargestatusandmoneyCall.getJsonObject().getAsJsonObject("data").get("money").getAsDouble();
			
			Logger.verifyEquals(0.01, money,"未付费验证金额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchChargeStatusAndMoney_004() {
		Logger.start(true,"商户号为空，失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("mark", mchid);
            getmchchargestatusandmoneyBean.setMchId(mchid);
            
            
			getmchchargestatusandmoneyCall.setData(getmchchargestatusandmoneyBean);
			getmchchargestatusandmoneyCall.callService();			
			Logger.verifyEquals("200", getmchchargestatusandmoneyCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchChargeStatusAndMoney_005() {
		Logger.start(true,"商户修改信息，查看付费状态");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("mark", mchid);
            getmchchargestatusandmoneyBean.setMchId(mchid);
            
			getmchchargestatusandmoneyCall.setData(getmchchargestatusandmoneyBean);
			getmchchargestatusandmoneyCall.callService();			
			Logger.verifyEquals("200", getmchchargestatusandmoneyCall.getString("code"), "验证code");
			
			editmchBean initeditmachBean = GodmchManageCallService.IniteditmachBean(mchid);
			initeditmachBean.setMchTitle("hhhhhh");
			GodmchManageCallService.editmachCall(initeditmachBean);
			
			getmchchargestatusandmoneyCall.setData(getmchchargestatusandmoneyBean);
			getmchchargestatusandmoneyCall.callService();			
			Logger.verifyEquals("200", getmchchargestatusandmoneyCall.getString("code"), "验证code");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}